package com.mingqi.enetconnected.net.request;

import android.content.Context;
import android.text.TextUtils;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.mingqi.enetconnected.data.bean.emp.EmpIdCode;
import com.mingqi.enetconnected.data.bean.emp.EmpInfo;
import com.mingqi.enetconnected.data.bean.emp.EmpMonthWorkloadStatistics;
import com.mingqi.enetconnected.data.bean.emp.EmpPromotionCode;
import com.mingqi.enetconnected.data.bean.emp.EmpYearWorkloadStatistics;
import com.mingqi.enetconnected.util.JsonUtils;

import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.List;

/**
 * EmpRemoteService
 * 共6个，已完成
 */
public class EmpRemoteRequest {
    /**
     * 查询员工信息
     */
    public final static String EMP_INFO = "/v1/crm-service/staff/info";
    /**
     * 员工识别码
     */
    public final static String IDENTIFICATION_CODE = "/v1/crm-service/staff/identificationCode";
    /**
     * 获取员工推广二维码
     */
    public static final String PROMOTION_CODE = "/v1/crm-service/staff/promotionCode";

    /**
     * 员工年度工作量统计
     */
    public final static String YEAR_WORKS = "/v1/crm-service/statistics/yearWorks";
    /**
     * 员工年度月工作量统计
     */
    public final static String YEARMONTH_WORKS = "/v1/crm-service/statistics/yearMonthWorks";
    /**
     * 实时统计员工某月工作量
     */
    public final static String DAY_WORKS = "/v1/crm-service/statistics/dayWorks";

    /**
     * 查询员工信息
     *
     * @param cxt
     * @return
     * @throws Exception
     */
    public static EmpInfo getEmpInfo(Context cxt) throws Exception {
        Type type = new TypeToken<EmpInfo>() {
        }.getType();
        Communicator<EmpInfo> communicator = new Communicator<>(cxt, EMP_INFO);
        return communicator.get(type);
    }

    /**
     * 获取员工识别码
     *
     * @param cxt
     * @return
     * @throws Exception
     */
    public static EmpIdCode getIdentificationCode(Context cxt) throws Exception {
        Type type = new TypeToken<EmpIdCode>() {
        }.getType();
        Communicator<EmpIdCode> communicator = new Communicator<>(cxt, IDENTIFICATION_CODE);
        return communicator.get(type);
    }

    /**
     * 获取员工推广二维码
     *
     * @param cxt
     * @return
     * @throws Exception
     */
    public static EmpPromotionCode getPromotionCode(Context cxt) throws Exception {
        Type type = new TypeToken<EmpPromotionCode>() {
        }.getType();
        Communicator<EmpPromotionCode> communicator = new Communicator<>(cxt, PROMOTION_CODE);
        return communicator.get(type);
    }

    /**
     * 员工年度工作量统计
     *
     * @param cxt
     * @param year 年，yyyy ，默认为今年
     * @return
     * @throws Exception
     */
    public static EmpYearWorkloadStatistics getYearWorks(Context cxt, String year) throws Exception {
        Type type = new TypeToken<EmpYearWorkloadStatistics>() {
        }.getType();
        Communicator<EmpYearWorkloadStatistics> communicator = new Communicator<>(cxt, YEAR_WORKS);
        if (TextUtils.isEmpty(year)) {
            return communicator.get(type);
        }
        HashMap<String, String> params = new HashMap<>();
        params.put("year", year);
        return communicator.get(params, type);
    }

    /**
     * 员工年度工作量统计(当年)
     *
     * @param cxt
     * @return
     * @throws Exception
     */
    public static EmpYearWorkloadStatistics getYearWorks(Context cxt) throws Exception {
        return getYearWorks(cxt, null);
    }

    /**
     * 员工年度月工作量统计
     *
     * @param cxt
     * @param startYearMonth yyyyMM
     * @param endYearMonth   yyyyMM
     * @return
     * @throws Exception
     */
    public static EmpMonthWorkloadStatistics getYearMonthWorks(Context cxt, String startYearMonth, String endYearMonth) throws Exception {
        Type type = new TypeToken<EmpMonthWorkloadStatistics>() {
        }.getType();
        Communicator<EmpMonthWorkloadStatistics> communicator = new Communicator<>(cxt, YEARMONTH_WORKS);
        HashMap<String, String> params = new HashMap<>();
        params.put("yearMonth", startYearMonth + "," + endYearMonth);
        return communicator.get(params, type);
    }

    /**
     * 实时统计员工某月工作量
     *
     * @param cxt
     * @param yearMonth yyyyMM
     * @return
     * @throws Exception
     */
    public static List<EmpMonthWorkloadStatistics> getYearmonthWorks(Context cxt, String yearMonth) throws Exception {
        Type type = new TypeToken<List<EmpMonthWorkloadStatistics>>() {
        }.getType();
        Communicator<List<EmpMonthWorkloadStatistics>> communicator = new Communicator<>(cxt, DAY_WORKS);
        HashMap<String, String> params = new HashMap<>();
        params.put("yearMonth", yearMonth);

        return communicator.get(params, type);
    }
}
